Timeout expired - storing images
Hello,
I have a problem with my report using images.
First step is creating empty report with some text and so on,but no images. Report file is saved in MSSQL 2005 DB.
In second step we are adding image. Here comes the problem part.
DataColumn for storing reports is: reportData of type IMAGE,-"Variable-length binary data from 0 through 2^31-1 (2,147,483,647) bytes."
2 test pictures:
- JPG - 37 kB
- BMP - 22 kB
CommandTimeout set to: 120
Test results:
Add picture to the report causes exception: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding
Error occured in cca 30s.
So realy small size pictures cause timeout expired exception...
Some interesting notice:
For JPG - it allowes save only one time,than error with adding anything to the report and saving again
For BMP - 11 pictures added next to each other Ok, add 12th error
Way of storing data to DB:
Do you know where should be the problem? Maybe manual Connection closing? Another type of DB reportData? MemoryStream???
Thanx
I have a problem with my report using images.
First step is creating empty report with some text and so on,but no images. Report file is saved in MSSQL 2005 DB.
In second step we are adding image. Here comes the problem part.
DataColumn for storing reports is: reportData of type IMAGE,-"Variable-length binary data from 0 through 2^31-1 (2,147,483,647) bytes."
2 test pictures:
- JPG - 37 kB
- BMP - 22 kB
CommandTimeout set to: 120
Test results:
Add picture to the report causes exception: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding
Error occured in cca 30s.
So realy small size pictures cause timeout expired exception...
Some interesting notice:
For JPG - it allowes save only one time,than error with adding anything to the report and saving again
For BMP - 11 pictures added next to each other Ok, add 12th error
Way of storing data to DB:
private void SaveReport(Report report, string reportName)
        {
            SqlCommand sqlcmd = MainConnection.connection.CreateCommand();
            sqlcmd.CommandText = "SELECT reportData FROM Reports WHERE reportName = @Name and formId = @Form";
            sqlcmd.Connection = MainConnection.connection;
            SqlParameter paramName = Utils.createParameter("Name", reportName);
            SqlParameter paramForm = Utils.createParameter("Form", formId);
           Â
            Utils.addParametersToCommand(sqlcmd, paramName, paramForm);
           Â
            sqlcmd.Connection.Open();
            SqlDataReader myReader = sqlcmd.ExecuteReader();
           Â
            if (myReader.Read())
            {
                using (MemoryStream stream1 = new MemoryStream())
                {
                    report.Save(stream1);
                    byte[] reportArray = stream1.ToArray();
                    SqlCommand sqlcmd2 = MainConnection.connection.CreateCommand();
                    MainConnection.connection.Open();
                    sqlcmd2.CommandText = "UPDATE Reports SET reportData=@stream WHERE reportName=@Name and formId=@Form";
                    SqlParameter paramStream = Utils.createParameter("stream", reportArray);
                    Utils.removeParametersFromCommand(sqlcmd, paramName, paramForm);
                    Utils.addParametersToCommand(sqlcmd2,paramStream,paramName,paramForm);
                    QueryUtils.runSql2(sqlcmd2);
                    if (saveToFile)
                    {
                        FileStream outStream = File.OpenWrite(reportName + ".frx");
                        stream1.WriteTo(outStream);
                        outStream.Flush();
                        outStream.Close();
                    }
                }
            }
            else {
                using (MemoryStream stream = new MemoryStream())
                {
                    report.ReportInfo.Name = reportName;
                    report.Save(stream);
                    byte[] reportArray = stream.ToArray();
                    SqlCommand sqlcmd2 = MainConnection.connection.CreateCommand();
                    MainConnection.connection.Open();
                    sqlcmd2.CommandText = "INSERT INTO Reports (formId,reportName,reportData) VALUES (" + formId + ",'" + reportName + "',@stream)";
                    SqlParameter paramStream = Utils.createParameter("stream", reportArray);
                    sqlcmd2.Parameters.Add(paramStream);
                    QueryUtils.runSql2(sqlcmd2);
                    if (saveToFile)
                    {
                        FileStream outStream = File.OpenWrite(reportName + ".frx");
                        stream.WriteTo(outStream);
                        outStream.Flush();
                        outStream.Close();
                    }
                }
            }
        }
AND
public static void runSql2(SqlCommand command)
        {
            command.Connection = MainConnection.connection;
            try
            {
                command.Connection.Open();
                command.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (command.Connection != null)
                command.Connection.Close();
        }
Do you know where should be the problem? Maybe manual Connection closing? Another type of DB reportData? MemoryStream???
Thanx
Comments
Problem is in not properly closed connection.close() ... It works fine now, Fastreport the BEST!!!
Sorry for bothering you
Hi , have a good day
Out of the subject , Why you open and close the connection every time you need to use it ,
for me I Open the connection at My Application start and never closed it , until my application exit
I heard something about pool [img]style_emoticons/<#EMO_DIR#>/huh.gif" style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /> c u[/img]